/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q0338.java
 * @Author : WangRuoyu
 * @Date 2023/1/12 11:08
 */

package leetcode;

import java.util.Arrays;

public class Q0338 {
    public int[] countBits(int n) {
        int[] res = new int[n + 1];

        res[0] = 0;
        for (int i = 0; i <= n; i++) {
            if (i % 2 == 1) {
                res[i] = res[i - 1] + 1;
            } else {
                res[i] = res[i / 2];
            }
        }

        return res;
    }

    public static void main(String[] args) {
        Q0338 sl = new Q0338();
        int n = 5;
        System.out.println(Arrays.toString(sl.countBits(n)));
    }
}
